package com.dreamoo.common.exception;

import com.dreamoo.common.result.ResultCode;

/**
 * 系统异常
 * 
 * @author dreamoo
 */
public class SystemException extends RuntimeException {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 错误码
     */
    private Integer code;
    
    /**
     * 错误消息
     */
    private String message;
    
    /**
     * 构造函数
     */
    public SystemException() {
        super(ResultCode.INTERNAL_SERVER_ERROR.getMessage());
        this.code = ResultCode.INTERNAL_SERVER_ERROR.getCode();
        this.message = ResultCode.INTERNAL_SERVER_ERROR.getMessage();
    }
    
    /**
     * 构造函数
     *
     * @param message 错误消息
     */
    public SystemException(String message) {
        super(message);
        this.code = ResultCode.INTERNAL_SERVER_ERROR.getCode();
        this.message = message;
    }
    
    /**
     * 构造函数
     *
     * @param message 错误消息
     * @param cause   异常原因
     */
    public SystemException(String message, Throwable cause) {
        super(message, cause);
        this.code = ResultCode.INTERNAL_SERVER_ERROR.getCode();
        this.message = message;
    }
    
    /**
     * 构造函数
     *
     * @param code    错误码
     * @param message 错误消息
     */
    public SystemException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }
    
    /**
     * 构造函数
     *
     * @param resultCode 结果状态码
     */
    public SystemException(ResultCode resultCode) {
        super(resultCode.getMessage());
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }
    
    /**
     * 获取错误码
     *
     * @return 错误码
     */
    public Integer getCode() {
        return code;
    }
    
    /**
     * 获取错误消息
     *
     * @return 错误消息
     */
    @Override
    public String getMessage() {
        return message;
    }
} 